home *** CD-ROM | disk | FTP | other *** search
- // *** Fire work Demostration Screen Saver Program ***
- // ***** Written by Steven De Toni Febyary 1996 ******
- // ***************************************************
-
- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- // ***** Include object information *****
- #include "config.h" // Configuration file define constants
- #include "ctl3d.h" // Fancey look to dialog boxes in Win3.1.
- #include "fclasses.h"
- #include "fix.h"
-
-
- // Program varibales !
- const char* pSzProgName = "Fire Work Screen Saver"; // Program name.
- const int StrSize = 256; // String size for string processing.
- static HINSTANCE HInst; // Handle to main window of application.
-
- // *** Prototypes ***
- long FAR PASCAL _export WndProc (HWND hWnd, WORD message, WORD wParam, LONG lParam);
- BOOL FAR PASCAL _export ConfigDialog (HWND hDlg, WORD message, WORD wParam, LONG lParam);
- BOOL FAR PASCAL _export SetPasswordDialog (HWND hDlg, WORD message, WORD wParam, LONG lParam);
- BOOL FAR PASCAL _export GetUserPDialog (HWND hDlg, WORD message, WORD wParam, LONG lParam);
- int UpdateField (HWND hDlg, int cntlID, int direction, int heightLimit, int lowLimit);
-
- // Spinner and field entry limits in configuration dialog.
- const int ObjRocketMax = 9000, ObjRocketMin = 0;
- const int ObjFlowerMax = 9000, ObjFlowerMin = 0;
- const int ObjFlareMax = 9000, ObjFlareMin = 1;
- const int ObjTrailerMax = 50, ObjTrailerMin = 1;
- const int ObjLifeMax = 2000, ObjLifeMin = 10;
- const int ObjPicSizeMax = 4, ObjPicSizeMin = 1;
-
- const int PicFreqMax = 10, PicFreqMin = 1;
- const int PicAngleMax = 20, PicAngleMin = -20;
- const int FrameRate = 0;
-
- // Default INI settings.
- const char* Section = "Configuration";
- const char* DefIniSettings = "1 50 10 50 1 50 10 100 1 ~ 0";
-
- // Timer ID constant.
- const int TIMERMAIN = 10; // Timer ID within function.
- const int TIMERABOUT = 11;
- const int TIMERCONFIG = 12;
-
- // Time limit variables for entering password.
- const long PASSWORDCYCLIMIT = 3000; // Timit limit to enter password before dialod is removed.
- static long CurrentCycle = 0;
- static HWND HPassDialog = NULL; // Varible used to commincate with
- // Password dialog box, and close it
- // after a certain time. If variable is
- // not null, then password dialog box is
- // open.
-
-
- // Current system screen size.
- int MAXX, MAXY;
-
- // Configuration variables for screen saver.
- // These variables are stored in the INI file (win.ini)
- static int RocketNum;
- static int RocketFlareNum;
- static int RocketTrailLen;
- static int RocketLifeCount;
-
- static int FlowerNum;
- static int FlowerFlareNum;
- static int FlowerTrailLen;
- static int FlowerLifeCount;
-
- extern int PixelSize; // Pixel size of objects, definied in class definition file.
-
- static char Password [StrSize/5];
- static int UsePassword;
-
-
- // ***************************************************************************************
- // Program Entry, and exit.
- // ***************************************************************************************
- int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
- {
- HWND hwnd;
- MSG msg;
- WNDCLASS wndclass;
- char paramBuff[StrSize];
-
- HInst = hInstance; // Assign program instance
- randomize();
-
- if (!hPrevInstance)
- {
- wndclass.style = CS_BYTEALIGNWINDOW | CS_HREDRAW | CS_VREDRAW;
- wndclass.lpfnWndProc = (WNDPROC) WndProc;
- wndclass.cbClsExtra = 0;
- wndclass.hInstance = HInst;
- wndclass.hIcon = NULL;
- wndclass.hCursor = LoadCursor (HInst, MAKEINTRESOURCE(BLANKCURSOR));
- wndclass.hbrBackground = GetStockObject (BLACK_BRUSH);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = pSzProgName;
-
- RegisterClass (&wndclass);
- }
- else
- return 0; // Don't more than one instance of the screen saver
-
- MAXX = GetSystemMetrics(SM_CXSCREEN);
- MAXY = GetSystemMetrics(SM_CYSCREEN);
-
- // Check parameter string for configuration command /c
- lstrcpy (paramBuff, lpszCmdParam);
- strupr (paramBuff);
- if (strstr (paramBuff, "/C") != NULL)
- {
- // Setup the control 3D sub-classing DLL.
- Ctl3dRegister(HInst);
- Ctl3dAutoSubclass(HInst);
-
- // Test Configuration Dialog.
- static FARPROC fpfnConfigDialog;
- fpfnConfigDialog = MakeProcInstance ((FARPROC)ConfigDialog, HInst);
- DialogBox (HInst, MAKEINTRESOURCE(IDD_CONFIGDIALOG), NULL, (DLGPROC) fpfnConfigDialog);
- FreeProcInstance (fpfnConfigDialog);
-
- // Free up usage count of 3D DLL.
- Ctl3dUnregister(HInst);
- return 0;
- }
-
- // Create Screen Saver window.
- hwnd = CreateWindowEx (WS_EX_TOPMOST,
- pSzProgName, // Window class name
- "", // Window caption
- WS_POPUP, // Window style
- 0, // inital X position
- 0, // inital y position
- MAXX, // inital X size
- MAXY, // intial y size
- NULL, // parent window handle
- NULL, // window menu handle
- HInst, // program instance handle
- NULL); // creation parameters
-
-
- // Setup Screen saver timer.
- SetTimer(hwnd, TIMERMAIN, FrameRate, (TIMERPROC) WndProc);
-
- // Go into screen saver mode.
- ShowWindow (hwnd, nCmdShow);
- UpdateWindow (hwnd);
-
- // Process screen saver messages...
- while (GetMessage (&msg, NULL, 0, 0))
- {
-
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
-
- return msg.wParam;
- }
-
- // Pic one of the primary colours
- COLORREF PicColour (void)
- {
- // select primary colour
- switch (random(7))
- {
- case 0:
- return RGB (255, 0, 0);
-
- case 1:
- return RGB (0, 255, 0);
-
- case 2:
- return RGB (0, 0, 255);
-
- case 3:
- return RGB (255, 255, 0);
-
- case 4:
- return RGB (0, 255, 255);
-
- case 5:
- return RGB (255, 0, 255);
-
- case 6:
- default:
- return RGB (255, 255, 255);
- }
- }
-
-
- // ***************************************************************************
- // *** Get User Password Dialog Box. Open up the dialog box to recieve the
- // *** user's password.
- // ***************************************************************************
- BOOL FAR PASCAL _export GetUserPDialog (HWND hDlg, WORD message, WORD wParam, LONG lParam)
- {
- switch (message)
- {
- case WM_INITDIALOG:
- HPassDialog = hDlg;
- CurrentCycle = 0;
- SetActiveWindow (GetDlgItem(hDlg, IDC_GETPASSWORD));
- return TRUE;
-
- case WM_CHAR:
- MessageBeep (-1);
- break;
-
- case WM_KEYDOWN:
- case WM_SYSKEYDOWN:
- return TRUE;
-
- case WM_COMMAND: // A user has selected a control command
- switch (LOWORD (wParam))
- {
- case IDC_CANCEL:
- EndDialog (hDlg, FALSE);
- HPassDialog = NULL;
- return TRUE;
-
- case IDC_OK:
- char testPass[StrSize/5];
-
- GetDlgItemText(hDlg, IDC_GETPASSWORD, testPass, StrSize/5);
- if (strcmp (Password, testPass) != 0)
- {
- MessageBeep(MB_ICONINFORMATION);
- SetWindowText (hDlg,"Password Incorrect. Retry Entry...");
- SetActiveWindow (GetDlgItem(hDlg, IDC_GETPASSWORD));
- break;
- }
-
- // If all checks pass ... exit!
- EndDialog (hDlg, TRUE);
- HPassDialog = NULL;
- return TRUE;
-
- default:
- break;
- }
- break;
-
- case WM_CLOSE:
- EndDialog (hDlg, 0);
- HPassDialog = NULL;
- return TRUE;
- }
-
- return FALSE;
- }
-
-
- // ***************************************************************************
- // *** Set Password Dialog Box.
- // *** Get user's password from within the configuration dialog box.
- // ***************************************************************************
- BOOL FAR PASCAL _export SetPasswordDialog (HWND hDlg, WORD message, WORD wParam, LONG lParam)
- {
- switch (message)
- {
- case WM_COMMAND: // A user has selected a control command
- switch (LOWORD (wParam))
- {
- case IDC_SETPASSWORD:
- char newPass[StrSize/5];
- char testPass[StrSize/5];
-
- GetDlgItemText(hDlg, IDC_NEWPASSWORD, newPass, StrSize/5);
- if (strlen (newPass) <= 0)
- {
- MessageBox (hDlg, "Please Enter A Password First", "*** Entry Error ***",
- MB_OK | MB_ICONINFORMATION);
- break;
- }
-
- GetDlgItemText(hDlg, IDC_RETYPEDPASSWORD, testPass, StrSize/5);
- if (strcmp (newPass, testPass) != 0)
- {
- MessageBox (hDlg, "New And Retyped Password Differ", "*** Check Error ***",
- MB_OK | MB_ICONINFORMATION);
- break;
- }
-
- // If all checks pass ... then use it !
- UsePassword = 1;
- strcpy (Password, testPass);
- EndDialog (hDlg, 1);
- break;
-
- case IDC_CANCELPASSWORD:
- EndDialog (hDlg, 0);
- break;
-
- default:
- break;
- }
- break;
-
- case WM_CLOSE:
- EndDialog (hDlg, 0);
- break;
- }
-
- return FALSE;
- }
-
-
- // ***************************************************************************
- // *** About Dialog Box.
- // *** Get user's password from within the configuration dialog box.
- // ***************************************************************************
- BOOL FAR PASCAL _export AboutDialog (HWND hDlg, WORD message, WORD wParam, LONG lParam)
- {
- const int flareNum = 150;
- static Flare* flares = NULL;
-
- static HDC virtHdc;
- static HRGN hNewClipRegion;
- static RECT clientRect;
- static HBITMAP hDrawBitmap, hOldBitmap;
- static HDC hdc;
-
- // Colour picking variables.
- const int cycleLimit = 100;
- static COLORREF currentCol;
- static int cycle;
-
- switch (message)
- {
- case WM_INITDIALOG:
-
- // implement timer.
- flares = NULL;
- flares = new Flare[flareNum];
-
- if (flares == NULL)
- {
- MessageBox (hDlg, "Out Of Memory", "Memory Problems",
- MB_OK | MB_ICONINFORMATION);
- PostMessage (hDlg, WM_CLOSE, 0, 0L);
- break; // memory allocate error
- }
-
- // set colour cycling
- currentCol = PicColour ();
- cycle = cycleLimit;
-
- hdc = GetDC (GetDlgItem (hDlg, IDC_MINIWORK));
- // Set map mode and get size of client area.
- SetMapMode (hdc, MM_TEXT);
- GetClientRect(GetDlgItem (hDlg, IDC_MINIWORK), &clientRect);
- clientRect.right-= 2; clientRect.bottom-= 2;
-
- virtHdc = CreateCompatibleDC (hdc);
- hDrawBitmap = CreateCompatibleBitmap (hdc, clientRect.right, clientRect.bottom);
- hOldBitmap = SelectObject (virtHdc, hDrawBitmap);
- SetMapMode (virtHdc, MM_TEXT);
-
- // Delete background.
- FillRect(virtHdc, &clientRect, GetStockObject(BLACK_BRUSH));
- hNewClipRegion = CreateRectRgn(clientRect.left, clientRect.top,
- clientRect.right, clientRect.bottom);
- SelectClipRgn(virtHdc, hNewClipRegion);
-
- SetTimer(hDlg, TIMERABOUT, FrameRate, (TIMERPROC) AboutDialog);
- break;
-
- case WM_TIMER:
- if (cycle < 0)
- {
- // reset colour cycling
- currentCol = PicColour ();
- cycle = cycleLimit;
- }
- else
- cycle--;
-
- for (int count = 0; count < flareNum; count++)
- {
- if (flares[count].move(virtHdc) == FALSE)
- {
- flares[count].init (clientRect.right >> 1, clientRect.bottom >> 1,
- ((random (40)-20) * Fixed) >> 2, ((random (40)-20) * Fixed) >> 2,
- random(50),
- clientRect.bottom-2, random(10)+5,
- currentCol);
- }
- }
-
- hdc = GetDC (GetDlgItem (hDlg, IDC_MINIWORK));
- // Blast virtual screen onto real screen.
- BitBlt (hdc, 1, 1, clientRect.right, clientRect.bottom,
- virtHdc, 0, 0,
- SRCCOPY);
- ReleaseDC (GetDlgItem (hDlg, IDC_MINIWORK), hdc);
- break;
-
- case WM_COMMAND: // A user has selected a control command
- switch (LOWORD (wParam))
- {
- case IDC_LEAVE:
- PostMessage (hDlg, WM_CLOSE, 0, 0L);
- }
- break;
-
- case WM_CLOSE:
- KillTimer(hDlg, TIMERABOUT);
- // Free objects.
- DeleteObject (hNewClipRegion);
- DeleteObject (SelectObject (virtHdc, hOldBitmap));
- DeleteDC (virtHdc);
- delete flares;
- EndDialog (hDlg, 0);
- break;
- }
-
- return FALSE;
- }
-
-
- // **********************************************************************************
- // Updated process spinner controls (aka: scroll bars).
- //
- // hDlg = handle to dialog box
- // cntlID = ID number of text field
- // direction = 1, for up, -1 for down, 0 = dont increment/decrement
- // heightLimit = max number (inclusive).
- // lowlimit = min number (inclusive).
- //
- // Returns integer value of field.
- int UpdateField (HWND hDlg, int cntlID, int direction, int heightLimit, int lowLimit)
- {
- char buffer[StrSize];
- int number;
-
- // Get text
- GetDlgItemText(hDlg, cntlID, buffer, StrSize);
-
- // convert string.
- number = atoi (buffer);
-
- // Check field constraints.
- if ((direction >= 1) && (number < heightLimit)) // Increment.
- number++;
- else
- if ((direction <= -1) && (number > lowLimit)) // Decrement.
- number--;
-
- // Implement simple limit, and error check from conversion from text.
- if (number > heightLimit)
- number = heightLimit;
- else if (number < lowLimit)
- number = lowLimit;
-
- // Redisplay number into field
- sprintf (buffer, "%d", number);
- SetDlgItemText(hDlg, cntlID, buffer);
-
- // return number value.
- return number;
- }
-
-
- // **********************************************************************************
- // Function to process scroll bar messages and update spinner fields.
- //
- // hDlg = handle to dialog box
- // wParam = Scroll bar message
- // lParam = control dialog handle
- //
- // returns TRUE if spinner message was processed,
- // FALSE if it wasn't.
- BOOL ProcessSpinners (HWND hDlg, WORD wParam, LONG lParam)
- {
- switch (wParam) // Find what type of action.
- {
- case SB_LINEDOWN:
- switch (GetDlgCtrlID(HIWORD(lParam))) /* handle of the control */
- {
- // Sky rocket number
- case IDC_ROCKNUMSPIN:
- UpdateField (hDlg, IDC_ROCKNUMEDIT, -1, ObjRocketMax, ObjRocketMin);
- return TRUE;
-
- // Rocket flare number
- case IDC_ROCKFNUMSPIN:
- UpdateField (hDlg, IDC_ROCKFNUMEDIT, -1, ObjFlareMax, ObjFlareMin);
- return TRUE;
-
- // Rocket Trail Length
- case IDC_ROCKTNUMSPIN:
- UpdateField (hDlg, IDC_ROCKTNUMEDIT, -1, ObjTrailerMax, ObjTrailerMin);
- return TRUE;
-
- // Rocket Life Counter
- case IDC_ROCKLNUMSPIN:
- UpdateField (hDlg, IDC_ROCKLNUMEDIT, -1, ObjLifeMax, ObjLifeMin);
- return TRUE;
-
- // *****************************************************************************
-
- // Flower pot number
- case IDC_FLOWERNUMSPIN:
- UpdateField (hDlg, IDC_FLOWERNUMEDIT, -1, ObjFlowerMax, ObjFlowerMin);
- return TRUE;
-
- // Rocket flare number
- case IDC_FLOWERFNUMSPIN:
- UpdateField (hDlg, IDC_FLOWERFNUMEDIT, -1, ObjFlareMax, ObjFlareMin);
- return TRUE;
-
- // Rocket Trail Length
- case IDC_FLOWERTNUMSPIN:
- UpdateField (hDlg, IDC_FLOWERTNUMEDIT, -1, ObjTrailerMax, ObjTrailerMin);
- return TRUE;
-
- // Rocket Life Counter
- case IDC_FLOWERLNUMSPIN:
- UpdateField (hDlg, IDC_FLOWERLNUMEDIT, -1, ObjLifeMax, ObjLifeMin);
- return TRUE;
-
- // Pixel Size Counter
- case IDC_PIXELSIZESPIN:
- UpdateField (hDlg, IDC_PIXELSIZEEDIT, -1, ObjPicSizeMax, ObjPicSizeMin);
- return TRUE;
-
- // *****************************************************************************
-
- // Picture frequency and angle spinners.
- case IDC_PICFREQSPIN:
- UpdateField (hDlg, IDC_PICFREQEDIT, -1, PicFreqMax, PicFreqMin);
- return TRUE;
-
- case IDC_PICANGLESPIN:
- UpdateField (hDlg, IDC_PICANGLEEDIT, -1, PicAngleMax, PicAngleMin);
- return TRUE;
- }
- break;
-
- case SB_LINEUP:
- switch (GetDlgCtrlID(HIWORD(lParam))) /* handle of the control */
- {
- // Sky rocket number
- case IDC_ROCKNUMSPIN:
- UpdateField (hDlg, IDC_ROCKNUMEDIT, 1, ObjRocketMax, ObjRocketMin);
- return TRUE;
-
- // Rocket flare number
- case IDC_ROCKFNUMSPIN:
- UpdateField (hDlg, IDC_ROCKFNUMEDIT, 1, ObjFlareMax, ObjFlareMin);
- return TRUE;
-
- // Rocket Trail Length
- case IDC_ROCKTNUMSPIN:
- UpdateField (hDlg, IDC_ROCKTNUMEDIT, 1, ObjTrailerMax, ObjTrailerMin);
- return TRUE;
-
- // Rocket Life Counter
- case IDC_ROCKLNUMSPIN:
- UpdateField (hDlg, IDC_ROCKLNUMEDIT, 1, ObjLifeMax, ObjLifeMin);
- return TRUE;
-
- // *****************************************************************************
-
- // Flower pot number
- case IDC_FLOWERNUMSPIN:
- UpdateField (hDlg, IDC_FLOWERNUMEDIT, 1, ObjFlowerMax, ObjFlowerMin);
- return TRUE;
-
- // Rocket flare number
- case IDC_FLOWERFNUMSPIN:
- UpdateField (hDlg, IDC_FLOWERFNUMEDIT, 1, ObjFlareMax, ObjFlareMin);
- return TRUE;
-
- // Rocket Trail Length
- case IDC_FLOWERTNUMSPIN:
- UpdateField (hDlg, IDC_FLOWERTNUMEDIT, 1, ObjTrailerMax, ObjTrailerMin);
- return TRUE;
-
- // Rocket Life Counter
- case IDC_FLOWERLNUMSPIN:
- UpdateField (hDlg, IDC_FLOWERLNUMEDIT, 1, ObjLifeMax, ObjLifeMin);
- return TRUE;
-
- // Pixel Size Counter
- case IDC_PIXELSIZESPIN:
- UpdateField (hDlg, IDC_PIXELSIZEEDIT, 1, ObjPicSizeMax, ObjPicSizeMin);
- return TRUE;
-
- // *****************************************************************************
-
- // Picture frequency and angle spinners.
- case IDC_PICFREQSPIN:
- UpdateField (hDlg, IDC_PICFREQEDIT, 1, PicFreqMax, PicFreqMin);
- return TRUE;
-
- case IDC_PICANGLESPIN:
- UpdateField (hDlg, IDC_PICANGLEEDIT, 1, PicAngleMax, PicAngleMin);
- return TRUE;
- }
- break;
- }
-
- return FALSE;
- }
-
- // **********************************************************************************
- // Function used to retrieve the field values from the configuration dialog box,
- // and place them into the INI configuration (global) variables. Used in
- // save INI settings.
- void GetFieldInfo (HWND hDlg)
- {
-
- // Get configuration information.
- RocketNum = UpdateField (hDlg, IDC_ROCKNUMEDIT, 0, ObjRocketMax, ObjRocketMin);
- RocketFlareNum = UpdateField (hDlg, IDC_ROCKFNUMEDIT, 0, ObjFlareMax, ObjFlareMin);
- RocketTrailLen = UpdateField (hDlg, IDC_ROCKTNUMEDIT, 0, ObjTrailerMax, ObjTrailerMin);
- RocketLifeCount = UpdateField (hDlg, IDC_ROCKLNUMEDIT, 0, ObjLifeMax, ObjLifeMin);
-
- FlowerNum = UpdateField (hDlg, IDC_FLOWERNUMEDIT, 0, ObjFlowerMax, ObjFlowerMin);
- FlowerFlareNum = UpdateField (hDlg, IDC_FLOWERFNUMEDIT, 0, ObjFlareMax, ObjFlareMin);
- FlowerTrailLen = UpdateField (hDlg, IDC_FLOWERTNUMEDIT, 0, ObjTrailerMax, ObjTrailerMin);
- FlowerLifeCount = UpdateField (hDlg, IDC_FLOWERLNUMEDIT, 0, ObjLifeMax, ObjLifeMin);
-
- // Pixel Size Counter
- PixelSize = UpdateField (hDlg, IDC_PIXELSIZEEDIT, 0, ObjPicSizeMax, ObjPicSizeMin);
- }
-
-
- // mode = 0 to return current bitmap DC
- // 1 for intialise variables
- // 2 to free variables
- HDC LoadBitmap (int mode, BITMAP& bmp, HBITMAP hTitle = 0, HWND hWnd = 0)
- {
- static HBITMAP hOldBmp;
- static HDC hdcSrc = NULL;
-
- switch (mode)
- {
- case 0:
- break;
-
- case 1:
- HDC hdcDest = GetDC(hWnd);
-
- hdcSrc = CreateCompatibleDC(hdcDest);
- GetObject(hTitle, sizeof(BITMAP), &bmp);
- hOldBmp = SelectObject(hdcSrc, hTitle);
- SetMapMode (hdcSrc, MM_TEXT);
- RealizePalette(hdcSrc);
- ReleaseDC (hWnd, hdcDest);
- break;
-
- case 2:
- SelectObject (hdcSrc, hOldBmp);
- DeleteDC (hdcSrc);
- hdcSrc = NULL;
- break;
- }
-
- return hdcSrc;
- }
-
- // mode = 0 to return current bitmap DC
- // 1 for intialise variables
- // 2 to free variables
- HDC CreateVirtualHDC (int mode, HWND hWnd = 0)
- {
- static HDC virtHdc = NULL;
- static HBITMAP hDrawBitmap, hOldBitmap;
-
- switch (mode)
- {
- case 0:
- break;
-
- case 1:
- HDC hdcDest = GetDC (hWnd);
- RECT clientRect;
-
- // Set map mode and get size of client area.
- SetMapMode (hdcDest, MM_TEXT);
- GetClientRect(hWnd, &clientRect);
-
- virtHdc = CreateCompatibleDC (hdcDest);
- SetMapMode (virtHdc, MM_TEXT);
- hDrawBitmap = CreateCompatibleBitmap (hdcDest,
- clientRect.right,
- clientRect.bottom);
-
- hOldBitmap = SelectObject (virtHdc, hDrawBitmap);
- SetMapMode (virtHdc, MM_TEXT);
-
- FillRect(virtHdc, &clientRect, GetStockObject(BLACK_BRUSH));
- ReleaseDC (hWnd, hdcDest);
- break;
-
- case 2:
- DeleteObject (SelectObject (virtHdc, hOldBitmap));
- DeleteDC (virtHdc);
- virtHdc = NULL;
- }
-
- return virtHdc;
- }
-
- void SinePic (int xPos, int yPos, int freq, unsigned int startAngle,
- BITMAP& bmp, HDC hdcBitmap, HDC hdcDisplay, HDC hdcVirtual)
- {
- int sPos = startAngle;
- int yPut;
- long mid = bmp.bmHeight >> 1;
-
- HBRUSH blkBrush;
- RECT blankArea;
-
- // erase old picture from virtual memory
- blankArea.left = xPos;
- blankArea.top = yPos - (bmp.bmHeight >> 1);
- blankArea.right = xPos + bmp.bmWidth;
- blankArea.bottom = yPos + bmp.bmHeight + (bmp.bmHeight >> 1);
-
- blkBrush = CreateSolidBrush (GetSysColor(COLOR_BTNFACE));
- // FillRect (hdcDisplay, &blankArea, blkBrush);
- FillRect (hdcVirtual, &blankArea, blkBrush);
- DeleteObject (blkBrush);
-
- for (int count = bmp.bmWidth + xPos; count > xPos; count--)
- {
- yPut = ((int) (SIN (sPos % NUMOFDEGREES) * mid) >> SHIFT) + yPos;
-
- // Plaster bitmap onto sine wave!
- BitBlt (hdcVirtual, count, yPut, 1, bmp.bmHeight,
- hdcBitmap, count-xPos, 0, SRCCOPY);
-
- sPos += freq;
- }
-
- // Blast virtual screen onto real display
- BitBlt (hdcDisplay, blankArea.left, blankArea.top, bmp.bmWidth, (bmp.bmHeight << 1) - 1,
- hdcVirtual, blankArea.left, blankArea.top, SRCCOPY);
- }
-
-
- // ***************************************************************************
- // *** Configuration Dialog Box.
- BOOL FAR PASCAL _export ConfigDialog (HWND hDlg, WORD message, WORD wParam, LONG lParam)
- {
- // used to read in configuration settings.
- char profileBuff[StrSize * 2];
-
- BOOL success;
- int bytesRead;
-
- // ****** Bitmap Sinus variables *****
- static HBITMAP hTitle = NULL;
- static BITMAP bmp;
- static unsigned int curAngle;
- static int freqInc;
- static int angleInc;
- static int picPutY;
- static int picPutX;
-
- switch (message)
- {
- case WM_INITDIALOG:
- // Read in INI settings and display these in fields.
- GetProfileString(pSzProgName, Section,
- DefIniSettings, profileBuff, StrSize * 2);
- sscanf (profileBuff, "%d %d %d %d %d %d %d %d %d %s %d",
- &RocketNum, &RocketFlareNum,
- &RocketTrailLen, &RocketLifeCount,
-
- &FlowerNum, &FlowerFlareNum,
- &FlowerTrailLen, &FlowerLifeCount,
- &PixelSize,
-
- Password, &UsePassword);
-
- // Setup password settings.
- CheckDlgButton(hDlg, IDC_SETPASSWORD, UsePassword);
- EnableWindow(GetDlgItem(hDlg, IDC_LOADPWDIALOG), (BOOL) UsePassword);
-
- // Set Parameters into feilds.
- SetDlgItemInt(hDlg, IDC_ROCKNUMEDIT, RocketNum, TRUE);
- SetDlgItemInt(hDlg, IDC_ROCKFNUMEDIT, RocketFlareNum, TRUE);
- SetDlgItemInt(hDlg, IDC_ROCKTNUMEDIT, RocketTrailLen, TRUE);
- SetDlgItemInt(hDlg, IDC_ROCKLNUMEDIT, RocketLifeCount, TRUE);
-
- SetDlgItemInt(hDlg, IDC_FLOWERNUMEDIT, FlowerNum, TRUE);
- SetDlgItemInt(hDlg, IDC_FLOWERFNUMEDIT, FlowerFlareNum, TRUE);
- SetDlgItemInt(hDlg, IDC_FLOWERTNUMEDIT, FlowerTrailLen, TRUE);
- SetDlgItemInt(hDlg, IDC_FLOWERLNUMEDIT, FlowerLifeCount, TRUE);
-
- SetDlgItemInt(hDlg, IDC_PIXELSIZEEDIT, PixelSize, TRUE);
-
-
- // Setup scrolling bitmap.
- // ***********************
- // Load bitmap from resources.
-
- hTitle = LoadBitmap (HInst, MAKEINTRESOURCE (IDB_TITLE));
-
- // Setup bitmap DC
- LoadBitmap (1, bmp, hTitle, hDlg);
-
- // Setup virtual DC
- CreateVirtualHDC (1, hDlg);
-
- // Set position variables,
- RECT clientRect;
- GetClientRect (hDlg, &clientRect); // Get size of client area
- picPutY = 40;
- picPutX = (clientRect.right / 2) - (bmp.bmWidth / 2);
-
- // Set incremental variables,
- freqInc = 2;
- angleInc = 5;
- SetDlgItemInt(hDlg, IDC_PICFREQEDIT, freqInc, TRUE);
- SetDlgItemInt(hDlg, IDC_PICANGLEEDIT, angleInc, TRUE);
-
- curAngle = 0;
-
- // Set timer
- SetTimer(hDlg, TIMERCONFIG, FrameRate, (TIMERPROC) ConfigDialog);
- return TRUE;
-
- // Process Scroll Bitmap
- case WM_TIMER:
- HDC dispDC = GetDC (hDlg);
-
- // sinus scroll bitmap onto display DC
- SinePic (picPutX, picPutY,
- freqInc, curAngle % NUMOFDEGREES, bmp,
- LoadBitmap (0, bmp),
- dispDC, CreateVirtualHDC(0)
- );
- ReleaseDC (hDlg, dispDC);
-
- curAngle+= angleInc;
- break;
-
- // Process spinner (AKA: scroll bars) controls.
- case WM_VSCROLL:
-
- // Update picture sinus scroll increment variables.
- if (ProcessSpinners (hDlg, wParam, lParam) != FALSE)
- {
- // Update these variables on every spinner message
- freqInc = UpdateField (hDlg, IDC_PICFREQEDIT, 0, PicFreqMax, PicFreqMin);
- angleInc = UpdateField (hDlg, IDC_PICANGLEEDIT, 0, PicAngleMax, PicAngleMin);
- }
- break;
-
- case WM_COMMAND: // A user has selected a control command
- switch (LOWORD (wParam))
- {
- case IDC_SETPASSWORD:
- if (UsePassword != 0)
- UsePassword = 0;
- else
- UsePassword = 1;
-
- CheckDlgButton(hDlg, IDC_SETPASSWORD, UsePassword);
- EnableWindow(GetDlgItem(hDlg, IDC_LOADPWDIALOG), (BOOL) UsePassword);
- break;
-
- case IDC_LOADPWDIALOG:
- // Test Configuration Dialog.
- static FARPROC fpfnSetPasswordDialog;
- fpfnSetPasswordDialog = MakeProcInstance ((FARPROC)SetPasswordDialog, HInst); // Place in window constructor
- DialogBox (HInst, MAKEINTRESOURCE(IDD_NEWPASSWORD), hDlg, (DLGPROC) fpfnSetPasswordDialog);
- FreeProcInstance (fpfnSetPasswordDialog);
- break;
-
- case IDC_SETIT: // Save settings.
- // Get user data.
- GetFieldInfo (hDlg);
-
- // Write settings to profile string.
- sprintf (profileBuff, "%d %d %d %d %d %d %d %d %d %s %d",
- RocketNum, RocketFlareNum,
- RocketTrailLen, RocketLifeCount,
-
- FlowerNum, FlowerFlareNum,
- FlowerTrailLen, FlowerLifeCount,
- PixelSize,
-
- Password, UsePassword);
-
- success = WriteProfileString(pSzProgName, Section,
- profileBuff);
- if (success == FALSE)
- {
- MessageBox(hDlg, "Unable to save settings!",
- "*** Write Profile String ***",
- MB_ICONSTOP | MB_OK | MB_TASKMODAL);
- break;
- }
-
- case IDC_FORGETIT: // Don't save settings.
- EndDialog (hDlg, 0);
- break;
-
- case IDC_ABOUT:
- static FARPROC fpfnAboutDialog;
-
- KillTimer(hDlg, TIMERCONFIG);
- fpfnAboutDialog = MakeProcInstance ((FARPROC)AboutDialog, HInst); // Place in window constructor
- // Get current pixel size.
- PixelSize = UpdateField (hDlg, IDC_PIXELSIZEEDIT, 0, ObjPicSizeMax, ObjPicSizeMin);
- DialogBox (HInst, MAKEINTRESOURCE(IDD_ABOUT), hDlg, (DLGPROC) fpfnAboutDialog);
- FreeProcInstance (fpfnAboutDialog);
- SetTimer(hDlg, TIMERCONFIG, FrameRate, (TIMERPROC) ConfigDialog);
- break;
-
- default:
- break;
- }
- break;
-
- case WM_CLOSE:
- KillTimer(hDlg, TIMERCONFIG);
- LoadBitmap (2, bmp);
- CreateVirtualHDC (2);
- DeleteObject (hTitle);
-
- EndDialog (hDlg, 0);
- break;
- }
-
- return FALSE;
- }
-
- // ***************************************************************************************
- // ******************************* Screen Saver function *********************************
- // **** Message Main dispatcher ! ****
- long FAR PASCAL _export WndProc (HWND hWnd, WORD message, WORD wParam, LONG lParam)
- {
- // Password checking routines
- const LONG testPW = 0xffff; // internal private message to init password entry.
- static semiphore = 0; // Only one password entry can exist, this is incremented
- // to indicated such. (i.e. windows sends multiple useless
- // messages that required to method to be here).
-
- // Object variables.
- static SkyRocket* pMyRockets = NULL;
- static FlowerPot* pMyPots = NULL;
- char profileBuff[StrSize * 2];
- static int count;
-
- // Store last mouse positions, and check if it's changed.
- static POINT lastMPos;
-
- switch (message)
- {
- // Window Constructor
- case WM_CREATE:
- // Read in INI settings and display these in fields.
- GetProfileString(pSzProgName, Section,
- DefIniSettings, profileBuff, StrSize * 2);
- sscanf (profileBuff, "%d %d %d %d %d %d %d %d %d %s %d",
- &RocketNum, &RocketFlareNum,
- &RocketTrailLen, &RocketLifeCount,
-
- &FlowerNum, &FlowerFlareNum,
- &FlowerTrailLen, &FlowerLifeCount,
- &PixelSize,
-
- Password, &UsePassword);
-
-
- // Allocate memory for objects .... only in local heap though.
- pMyRockets = new SkyRocket[RocketNum];
- pMyPots = new FlowerPot[FlowerNum];
-
- if ((pMyRockets == NULL) || (pMyPots == NULL))
- {
- delete pMyRockets, pMyPots;
-
- MessageBox (hWnd, "Unable to Allocate Memory!", "*** Memory Error ***",
- MB_OK | MB_TASKMODAL | MB_ICONSTOP);
- PostQuitMessage (0);
- return 0;
- }
-
-
- MAXY--; // Adjust so that ground is visible on screen.
- for (count = 0; count < RocketNum; count++)
- {
- pMyRockets[count].init (RocketFlareNum, // N.O of flares
- MAXX >> 1, MAXY, // x, y start location
- ((random (15)-7) * Fixed), // Horz thrust
- ((random (15)+10) * Fixed), // Vert thrust
- random(RocketLifeCount), // Life counter
- MAXY, // Ground
- RocketTrailLen, // Trailer Length
- PicColour () // colour
- );
- }
-
- for (count = 0; count < FlowerNum; count++)
- {
- pMyPots[count].init (FlowerFlareNum, // N.O of flares
- random(MAXX >> 1) + (MAXX >> 2), MAXY, // x, y start location
- PicColour (), // colour
- random(FlowerLifeCount >> 1) + (FlowerLifeCount >> 1), // Life counter
- FlowerTrailLen // Trailer Length
- );
- }
-
- // Get current mouse positions
- GetCursorPos(&lastMPos);
- ShowCursor (FALSE);
- break;
-
- case WM_TIMER:
- HDC hdc = GetDC (hWnd);
-
- // ########## Update Sky Rockets ##########
- for (count = 0; count < RocketNum; count++)
- {
- if (pMyRockets[count].move(hdc) == FALSE)
- {
- pMyRockets[count].init (RocketFlareNum, // N.O of flares
- MAXX >> 1, MAXY, // x, y start location
- ((random (15)-7) * Fixed), // Horz thrust
- ((random (15)+10) * Fixed), // Vert thrust
- random(RocketLifeCount), // Life counter
- MAXY, // Ground
- RocketTrailLen, // Trailer Length
- PicColour () // colour
- );
- }
- }
-
- // ########## Update Flower Pots ##########
- for (count = 0; count < FlowerNum; count++)
- {
- if (pMyPots[count].move(hdc) == FALSE)
- {
- pMyPots[count].init (FlowerFlareNum, // N.O of flares
- random(MAXX >> 1) + (MAXX >> 2), MAXY, // x, y start location
- PicColour (), // colour
- random(FlowerLifeCount >> 1) + (FlowerLifeCount >> 1),
- FlowerTrailLen // Trailer Length
- );
- }
- }
- ReleaseDC (hWnd, hdc);
-
- // If to long send password dialog box a close message.
- if (HPassDialog != NULL)
- {
- CurrentCycle++;
- if (CurrentCycle >= PASSWORDCYCLIMIT)
- {
- PostMessage (HPassDialog, WM_CLOSE, 0 ,0L);
- CurrentCycle = 0; // Make sure don't send message twice if system is slow.
- }
- }
- return TRUE;
-
- case WM_COMMAND:
- switch (lParam)
- {
- // Get user password...
- case testPW:
- static FARPROC fpfnGetUserPDialog;
- BOOL test;
-
- ShowCursor (TRUE);
- fpfnGetUserPDialog = MakeProcInstance ((FARPROC)GetUserPDialog, HInst);
- test = DialogBox (HInst, MAKEINTRESOURCE(IDD_GETUSERPASSWORD), hWnd, (DLGPROC) fpfnGetUserPDialog);
- FreeProcInstance (fpfnGetUserPDialog);
- ShowCursor (FALSE);
- if (test == 0)
- {
- // reset mouse pointer and return back to screen saver
- GetCursorPos(&lastMPos);
- SetActiveWindow (hWnd);
- }
- else
- PostMessage (hWnd, WM_CLOSE, 0, 0L );
- semiphore--; // Free up semiphore.
- return TRUE;
- }
- break;
-
- case WM_MOUSEMOVE:
- if ((LOWORD(lParam) == lastMPos.x) &&
- (HIWORD(lParam) == lastMPos.y))
- {
- break;
- }
-
- case WM_KEYDOWN:
- case WM_SYSKEYDOWN:
- case WM_LBUTTONDOWN:
- case WM_MBUTTONDOWN:
- case WM_RBUTTONDOWN:
- // Implement password check!
- if (semiphore == 0)
- {
- if ((UsePassword != 0) && (strcmp (Password, "~") != 0))
- {
- semiphore++; // Implement locking action.
- PostMessage (hWnd, WM_COMMAND, 0, testPW);
- break;
- }
- PostMessage (hWnd, WM_CLOSE, 0, 0L );
- }
- break;
-
-
- case WM_CLOSE:
- case WM_DESTROY:
- // delete pMyBall, pZDist;
- ShowCursor (TRUE);
- PostQuitMessage (0);
- return 0;
- }
-
- return DefWindowProc (hWnd, message, wParam, lParam);
- }
-